﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace InfoLogic.Models
{
    public class UserContext: DbContext
    {

        public UserContext()
            : base("name = DefaultConnection")
        {

        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Role>()
                .HasMany<UserProfile>(r => r.UserProfiles)
                .WithMany(u => u.Roles)
                .Map(m =>
                {
                    m.ToTable("webpages_UsersInRoles");
                    m.MapLeftKey("UserId");
                    m.MapRightKey("RoleId");
                });

           /* using (var db = new UserContext())
            {
                var memberships = db.Membership
                    .Include("UserProfile")
                    .Include("UserProfile.Roles")
                    .ToList();
                foreach (var member in memberships)
                {
                    //member.IsConfirmed = true;
                }

                //db.SaveChanges();
            }*/
        }

        public DbSet<Membership> Membership { get; set; }
        public DbSet<OAuthMembership> OAuthMembership { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<UserProfile> UserProfiles { get; set; }
        public DbSet<Audit> Audit { get; set; }
        public DbSet<Business> Business { get; set; }
        public DbSet<Owner> Owner { get; set; }
        public DbSet<Manager> Manager { get; set; }
        public DbSet<Product> Product { get; set; }
        public DbSet<Sales> Sales { get; set; }
        public DbSet<Cart> Cart { get; set; }
        public DbSet<Order> Order { get; set; }
        public DbSet<OrderDetail> OrderDetail { get; set; }

    }

     
}